<template>
	<view :class="[primarySize()]">
		<view class="page-foot bg-white">
			<view class="foot_btn" @click="bindSubmit">
				<button hover-class="none" class="btn1">提交</button>
			</view>
		</view>
		<view class="container">
			<view class="clearfix label_main">
				<view class="label_item" :class="[item.check?'active':'']" @click="check(index)" v-for='(item,index) in benefits'>{{item.name}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				
				benefits: [
				],
				info:{}
			}
		},
		onReady() {
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: this.primaryColor()
			})
		},
		onLoad: function (options) {
			
		    this.getOpenerEventChannel().on('infoTransfer', data => {
		      this.info = data.info;
		      this.$util.getBenefits().then(benefits=>{
		        benefits.forEach((item)=>{
		          for(let i=0;i<this.info.benefits.length;i++) {
		            if(item.id==this.info.benefits[i].id) {
		              item.check = true;
		            }
		          }
		        });
		        this.benefits = benefits;
		      });
		    });
		},
		methods: {
			check:function(index){
			    this.benefits[index].check = !this.benefits[index].check;
			    this.$forceUpdate()
			},
			bindSubmit() {
			    let benefits = [];
			    this.benefits.forEach(item=>{
			      if(item.check) {
			        benefits.push(item);
			      }
			    });
			    this.info.benefits = benefits;
			    this.getOpenerEventChannel().emit('infoTransfer',{info:this.info});
			    uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.label_item {
		font-size: 24rpx;
		color: #666;
		border-radius: 29rpx;
		line-height: 58rpx;
		text-align: center;
		float: left;
		min-width: 160rpx;
		padding: 0 20rpx;
		box-sizing: border-box;
		margin: 0 8rpx 27rpx;
		background-color: #F4F4F4
	}

	.label_main {
		padding-top: 37rpx;
		padding-left: 22rpx;
		padding-right: 22rpx;
	}

	.label_item.active {
		background-color: var(--primary);
		color: #fff;
	}

	.foot_btn {
		padding: 10rpx 30rpx;
	}

	.foot_btn button {
		margin-left: 0
	}
</style>